var app = getApp(),
  a = app.requirejs('core');
var loading=false;
Page({
    data: {
        form: {
            name: "",
            mobile: ""
        },
        show:false,
        img: "../../images/img-share-un.png",
        agree: 0
    },
    onLoad: function(e) {
      var that = this;
      a.ReName(e.title);
      that.setData({
        share_setting: app.getCache('shareSetting')
      })
      that.getInfo()
    },
    getInfo:function(){
      var that = this;
      a.get('Distribe/userinfo', { uid: app.getCache('userinfo').uid }, function (t) {
        if (t.code == 0) {
          that.setData({
            user_info: t.info,
            show: true
          })
        } else {
          a.alert(t.msg, function () {
            a.jump('', 5)
          })
        }
      }, true)
    },
    formSubmit: function(e) {
      if (loading) {
        return;
      }
      var that = this;
      if (that.data.form = e.detail.value, null != that.data.form.name && "" != that.data.form.name) if (null != that.data.form.mobile && "" != that.data.form.mobile) {
            var o = e.detail.value;
        o.form_id = e.detail.formId, 0 != that.data.agree ? (console.log(that.data.agree), 
          a.loading('正在提交'),
          o.user_id=app.getCache('userinfo').uid,
          loading = true,
          a.get('Distribe/join',o,function(t){
          a.hideLoading();
          loading=false;
          if(t.code==0){
              a.success('申请成功');
              if (t.share_condition==1){
                  setTimeout(function () {
                      that.getInfo();
                  }, 1e3)
              }else{
                  a.jump('../index/index',2);
              }
            }else{
              a.alert(t.msg,function(){
                that.getInfo();
              })
            }
          })
 ) : a.warning("请先阅读并确认分销申请协议！！");
      } else a.warning("请填写联系方式！"); else a.warning("请填写姓名！");
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    agreement: function() {
     var that=this;
        wx.showModal({
            title: "分销协议",
          content: that.data.share_setting.agree,
            showCancel: !1,
            confirmText: "我已阅读",
            confirmColor: "#ff4544",
            success: function(e) {
                e.confirm && console.log("用户点击确定");
            }
        });
    },
    agree: function() {
        var e = this, a = e.data.agree;
        0 == a ? (a = 1, e.setData({
            img: "../../images/img-share-agree.png",
            agree: a
        })) : 1 == a && (a = 0, e.setData({
            img: "../../images/img-share-un.png",
            agree: a
        }));
    }
});